#pragma once
#include"preCmpH.h"
#include"UIImage.h"
#include"UIFont.h"
#include"UIUtilities.h"

BEGIN_NAMESPACE(ui_manager)
class UIManager;
BEGIN_NAMESPACE(ui_graphics)

class UIRenderer;
typedef std::shared_ptr<UIRenderer> UIRendererPtr; // Shared pointer to manage dynamic UIImage objects

class UIRenderer
{
public:
//=====================================
// Constructors, Destructor, Operators
//=====================================
	UIRenderer();
	~UIRenderer();
//=====================================
// Functionality
//=====================================
	void StartUp(UIManager& manager);
	void ShutDown();
	UIImage* getImage(std::string name);
	UIImage& LoadImageFromFile(std::string name, std::string path);
	UIImage& GenerateImage(std::string name, int width,int height, bool transp, int hex_color);
	void DrawImage(int x, int y, int w, int h, const UIImage& img);
	void DrawTextToImage(std::string text, ui_fonts::UIFont& font,UIImage& save);
	void DisableClipping();
	void DrawLine(int x1, int y1, int x2, int y2, int _0xColor);
	void ClearImage(UIImage& img);
//=====================================
// Setters
//=====================================

	void setClipping(int x, int y, int w, int h);
	void setScreenSize(UISize size);
//=====================================
// Getters
//=====================================

	static UIRenderer& getInstance();

private:

	UIRenderer(const UIRenderer&); // denied
	UIRenderer& operator= (const UIRenderer&); // denied
	// hold the textures for different images
	// pass texture id to image
	std::list<UIImage*> images_;

	UISize size_;

	uint shader_program_;
	uint vertex_buffer_;
	uint texel_buffer_;
	
	uint pos_loc_;
	uint scale_loc_;
	uint color_loc_;
	uint texture_loc_;
	uint proj_matrix_loc_;

	float* matrix_;

	enum{RECTANGLE_START = 0,
		 RECTANGLE_STOP = 6,
		 LINE_START = 6,
		 LINE_STOP = 8
	};
};

END_NAMESPACE // UI manager
END_NAMESPACE // UI graphics